// 给定一个有 n 个节点的有向无环图，节点编号从 1 到 n。请编写一个函数，找出并返回所有从节点 1 到节点 n 的路径。每条路径应以节点编号的列表形式表示。

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});


let input = [];
rl.on('line', (line) => {
  input.push(line);
});

function processInput(input) {
  const [n, m] = input[0].split(' ').map(Number);
  const graph = new Array(n + 1).fill(0).map(() => []);
  for (let i = 1; i <= m; i++) {
    const [a, b] = input[i].split(' ').map(Number);
    if (!graph[a][b]) {
      graph[a].push(b);
    }
  }
 
  return graph;
  
}
rl.on('close',() => {
    const graph = processInput(input);
    console.log(graph)
    let ans = [];
    let path = [];
    let n = graph.length - 1;
    
    const dfs = (graph, index) => {
      if (index === n) {
        ans.push([...path]);
        return;
      }
      for (let i = 0; i < graph[index].length; i++) {
        path.push(graph[index][i]);
        dfs(graph, graph[index][i]);
        path.pop();
      }
    }
    path.push(1);
    dfs(graph, 1);
    return ans
    
})

rl.close();
